#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtGui

class Example(QtGui.QWidget):
    def __init__(self):
        super(Example, self).__init__()
        self.initUI()
    
    def initUI(self):
        okButton = QtGui.QPushButton("OK")
        cancelButton = QtGui.QPushButton("Cancel")
        
        hbox = QtGui.QHBoxLayout()
        # QHBoxLayout水平框布局
        hbox.addStretch(1)
        hbox.addWidget(okButton)
        hbox.addWidget(cancelButton)
        
        vbox = QtGui.QVBoxLayout()
        # QVBoxLayout垂直框布局
        vbox.addStretch(1)
        vbox.addLayout(hbox)
        
        # 窗体主布局
        self.setLayout(vbox)
        self.setWindowTitle('box layout')
        self.resize(300, 150)

app = QtGui.QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
